package com.apes.fico.engine.repository;

import com.apes.fico.engine.model.TempVoucher;
import com.apes.framework.jpa.repository.CustomRepository;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.query.Param;

import java.util.List;

public interface TempVoucherRepository extends CustomRepository<TempVoucher,String> {

    Page<TempVoucher> findTempVouchersByVoucherTemplateId(String voucherTemplateId, Pageable pageable);

    @Query(
            value = "SELECT MAX(T.ID) MaxId FROM GL_VOUCHER_TEMP T WHERE T.STATE = 0",
            nativeQuery = true
    )
    String findMaxIdByZeroState();


    @Query(
            value = "select t.id from TempVoucher t where t.id <= :id and  t.state = false and t.voucherTemplate.cycle = 'REAL_TIEM' order by t.id desc"
    )
    List<String> findFalseStateTempVouchersByIdLessThanEqual(@Param("id") String id, Pageable pageable);


}
